//
//  DeviceDetection.m
//  GUIResearch
//
//  Created by hcm-sd-imac5 on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DeviceDetection.h"
#include <sys/types.h>
#include <sys/sysctl.h>
@implementation DeviceDetection
+(NSString *) platform{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    return platform;
}

+ (int) platformbyInt{
    
    
    int iFlatformNumber=0;// unKnowflatform
    NSString *platform = [self platform];
    if ([platform isEqualToString:@"iPhone1,1"])    return 1;//@"iPhone 1G";
    if ([platform isEqualToString:@"iPhone1,2"])    return 2;//@"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    return 3;//@"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    return 4;//@"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"])    return 5;//@"Verizon iPhone 4";
    if ([platform isEqualToString:@"iPhone4,1"])    return 6;//@"iPhone 4S";
    if ([platform isEqualToString:@"iPod1,1"])      return 7;//@"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])      return 8;//@"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])      return 9;//@"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])      return 10;//@"iPod Touch 4G";
    if ([platform isEqualToString:@"iPad1,1"])      return 11;//@"iPad";
    if ([platform isEqualToString:@"iPad2,1"])      return 12;//@"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,2"])      return 13;//@"iPad 2 (GSM)";
    if ([platform isEqualToString:@"iPad2,3"])      return 14;// @"iPad 2 (CDMA)";
    if ([platform isEqualToString:@"i386"])         return 15;//@"Simulator";
    if ([platform isEqualToString:@"x86_64"])       return 16;//@"Simulator";
    return iFlatformNumber;
}
@end
